<?PHP
	/************************************************************************
	*       This file, in addition to all other parts of X7 Chat are        *
	*                   Copyright 2003-2007 by Tim Chamness.                *
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	* Version:          X7 Chat 3.0.0-A2                                    *
	* Release Date:     October 20, 2007                                    *
	* Author:           Tim Chamness                                        *
	* Copyright:        2003-2007 by Tim Chamness                           *
	* Website:          http://www.x7chat.com/                              *
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	* X7 Chat 3 is free software; you can redistribute it and/or modify     *
	* it under the terms of the GNU General Public License as published by  *
	* the Free Software Foundation; either version 3 of the License, or     *
	* (at your option) any later version.                                   *
	*                                                                       *
	* X7 Chat 3 is distributed in the hope that it will be useful, but      *
	* WITHOUT ANY WARRANTY; without even the implied warranty of            *
	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
	* General Public License for more details.                              *
	*                                                                       *
	* You should have received a copy of the GNU General Public License     *
	* along with this program.  If not, see <http://www.gnu.org/licenses/>. *
	*                                                                       *
	* Additional Terms, compatible with Section 7 of the GNU GPL v3,        *
	* apply to X7 Chat 3 and all X7 Chat 3 files, including this one.       *
	* You should have received a copy of these Additional Terms in the      *
	* file docs/COPYING.ADDITIONAL_TERMS.  If you did not receive a copy    *
	* please visit <http://www.x7chat.com/COPYING.ADDITIONAL_TERMS/>.       *
	************************************************************************/

	$GLOBALS['OUTPUT']->master_section = 'settings';
	$GLOBALS['OUTPUT']->minor_section = $GLOBALS['LANG']->lang_admin->integrationsettings;
	$GLOBALS['OUTPUT']->cpmenu = $menus[$GLOBALS['OUTPUT']->master_section];
	
	$form = new form();
	$form->add_field('text','foreignsys',$GLOBALS['LANG']->lang_admin->foreignsys);
	$form->add_field('text','localsys',$GLOBALS['LANG']->lang_admin->localsys);
	
	$other = $form->get_add_default('foreignsys');
	$x7chat = $form->get_add_default('localsys');
	if(!empty($other) && !empty($x7chat)){
		// Attempt to locate other script
		$other = parse_url($other);
		$x7chat = parse_url($x7chat);
		if(!$other || !$x7chat){
			$GLOBALS['OUTPUT']->message = $GLOBALS['LANG']->lang_admin->invalidurl;
		}else{
			if($other['host'] != $x7chat['host'])
				$GLOBALS['OUTPUT']->message = $GLOBALS['LANG']->lang_admin->invalidurl;
			else{
				$other = explode("/",$other['path']);
				$x7chat = explode("/",$x7chat['path']);
				
				for($i = 0; $i < count($other) && $i < count($x7chat); $i++){
					if($other[$i] != $x7chat[$i])
						break;
				}
				
				$path = '';
				for($x = $i; $x < count($x7chat)-1; $x++){
					$path .= "../";
				}
				
				for($x = $i; $x < count($other)-1; $x++){
					$path = $path."{$other[$x]}/";
				}
			}
		}
	}
	
	$localurl = 'http://'.preg_replace("#index.php\$#i",'',$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]);
	$foreign = 'http://'.$_SERVER["SERVER_NAME"].'/';
	
	$GLOBALS['OUTPUT']->supported_systems = 'none';
	$GLOBALS['OUTPUT']->form = $form->get_fields();
	
	echo tpl_integration::integration();
	//$GLOBALS['OUTPUT']->display('integration.php',array('supported_systems'=>'none','_FORM_DEFAULTS'=>array('localsys'=>$localurl,'foreignsys'=>$foreign)));
?>